# Copyright (c) 2022 - 2023 by Apex.AI Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0

load("@rules_cc//cc:defs.bzl", "cc_library")
load("//bazel:configure_file.bzl", "configure_file")

configure_file(
    name = "iceoryx_hoofs_deployment_hpp",
    src = "cmake/iceoryx_hoofs_deployment.hpp.in",
    out = "generated/include/iox/iceoryx_hoofs_deployment.hpp",
    config = {
        "IOX_IGNORE_32_BIT_CHECK_FLAG": "false",
        "IOX_MAX_NAMED_PIPE_MESSAGE_SIZE": "4096",
        "IOX_MAX_NAMED_PIPE_NUMBER_OF_MESSAGES": "10",
        # FIXME: for values see "iceoryx_hoofs/cmake/IceoryxHoofsDeployment.cmake" ... for now some nice defaults
        "IOX_MINIMAL_LOG_LEVEL": "TRACE",
    },
)

cc_library(
    name = "iceoryx_hoofs",
    srcs = glob([
        "cli/source/*.cpp",
        "concurrent/buffer/source/*.cpp",
        "design/source/*.cpp",
        "filesystem/source/*.cpp",
        "memory/source/*.cpp",
        "posix/auth/source/*.cpp",
        "posix/design/source/*.cpp",
        "posix/filesystem/source/*.cpp",
        "posix/ipc/source/*.cpp",
        "posix/sync/source/*.cpp",
        "posix/time/source/*.cpp",
        "posix/utility/source/*.cpp",
        "posix/vocabulary/source/*.cpp",
        "primitives/source/*.cpp",
        "reporting/source/*.cpp",
        "time/source/*.cpp",
        "utility/source/*.cpp",
        "vocabulary/source/**/*.cpp",
    ]),
    hdrs = glob(["buffer/**"]) + glob(["cli/**"]) + glob(["concurrent/**"]) + glob(["container/**"]) + glob(["design/**"]) + glob(["filesystem/**"]) + glob(["functional/**"]) + glob(["legacy/**"]) + glob(["memory/**"]) + glob(["posix/**"]) + glob(["primitives/**"]) + glob(["reporting/**"]) + glob(["time/**"]) + glob(["utility/**"]) + glob(["vocabulary/**"]) + [
        ":iceoryx_hoofs_deployment_hpp",
    ],
    includes = [
        "buffer/include/",
        "cli/include/",
        "concurrent/buffer/include/",
        "concurrent/sync/include/",
        "container/include/",
        "design/include",
        "filesystem/include",
        "functional/include",
        "generated/include",
        "legacy/include/",
        "memory/include/",
        "posix/auth/include/",
        "posix/design/include/",
        "posix/filesystem/include/",
        "posix/ipc/include/",
        "posix/sync/include/",
        "posix/time/include/",
        "posix/utility/include/",
        "posix/vocabulary/include/",
        "primitives/include/",
        "reporting/include/",
        "time/include/",
        "utility/include/",
        "vocabulary/include/",
    ],
    linkopts = select({
        "//iceoryx_platform:linux-clang": [
            "-latomic",
            "-lacl",
        ],
        "//iceoryx_platform:linux-gcc": ["-lacl"],
        "//iceoryx_platform:mac": [],
        "//iceoryx_platform:qnx": [],
        "//iceoryx_platform:unix": [],
        "//iceoryx_platform:win": [],
        "//conditions:default": ["-lacl"],
    }),
    visibility = ["//visibility:public"],
    deps = ["//iceoryx_platform"],
)

cc_library(
    name = "iceoryx_hoofs_testing",
    srcs = glob(["testing/**/*.cpp"]),
    hdrs = glob(["testing/include/**"]),
    strip_include_prefix = "testing/include",
    visibility = ["//visibility:public"],
    deps = [
        ":iceoryx_hoofs",
        "@googletest//:gtest",
    ],
)
